<html xmlns="http://www.w3.org/1999/xhtml" >
<%@ page language="java" import	="java.io.*,java.util.Date,java.text.SimpleDateFormat,java.util.Calendar,eSat.*" %>

<%@include file="dbcon.jsp"%>
<%
	int iMsgId = 1; 
	int iSno = 0;
	int iRecType = 0;
	String sCurrDate = "";
			
	String sTmp = request.getParameter("hid_RecType");
	if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
		iRecType = Integer.parseInt(sTmp);
	
	sTmp = request.getParameter("hid_RecSno");
	if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
		iSno = Integer.parseInt(sTmp);
	
	if ( sTmp == null || sTmp.equals("null") || sTmp.equals("") )
	{
		response.sendRedirect("frm_user.jsp");
		return;
	}
	
	try{
	
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	
		try {
			sCurrDate = dateFormat.format(calendar.getTime());
		} catch (Exception e) { e.printStackTrace(); }
		
		
		String sUserName	= request.getParameter("txt_uname");			
		String sPwd			= request.getParameter("txt_pwd");
		String sName		= request.getParameter("txt_name");
		String sAddress		= request.getParameter("ta_address");				
		String sContactNos	= request.getParameter("txt_contactno");
		String sEmail		= request.getParameter("txt_emailis");
		String sValidFDate 	= sCurrDate;
		String sValidTDate 	= sCurrDate;	
		
		int iRealestateFlag = 1;
		int iVechileFlag = 1;
		int iPersonFlag = 1;
		int iBusinessFlag = 1;
								
		sTmp = request.getParameter("ck_RealestateFlag");
		if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
			iRealestateFlag = 2;
		sTmp = request.getParameter("ck_VechileFlag");
		if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
			iVechileFlag = 2;
		sTmp = request.getParameter("ck_PersonFlag");
		if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
			iPersonFlag = 2;
		sTmp = request.getParameter("ck_BusinessFlag");
		if ( sTmp != null && !sTmp.equals("null") && !sTmp.equals("") )
			iBusinessFlag = 2;									
//System.out.println("ck_RealestateFlag : "+ request.getParameter("ck_RealestateFlag"));	
//System.out.println("ck_VechileFlag : "+ request.getParameter("ck_VechileFlag"));				
//System.out.println("ck_BusinessFlag : "+ request.getParameter("ck_BusinessFlag"));	
//System.out.println("ck_PersonFlag : "+ request.getParameter("ck_PersonFlag"));					
		
		if ( iRecType == 1 )
		{
			String sQry = "insert into tbl_user_master(user_name,pwd,person_name,address,contactno,emailid,valid_fdate,valid_tdate,";
			sQry += "realestate_flag,vechile_flag,person_flag,business_flag) values(";			
			sQry += "'"+ sUserName +"','"+ sPwd +"','"+ sName +"','"+ sAddress +"','"+ sContactNos +"','"+ sEmail +"',";
			sQry += "str_to_date('"+ sValidFDate.trim() + "','%d/%m/%Y'),";
			sQry += "str_to_date('"+ sValidTDate.trim() + "','%d/%m/%Y'),";	
			sQry += iRealestateFlag +","+ iVechileFlag +","+ iPersonFlag +","+ iBusinessFlag ;
			sQry += ")";			
		System.out.println("tbl_user_master Qry : "+ sQry);					

			Statement Stmt = Con.createStatement();
			Stmt.executeUpdate(sQry);
			if ( Stmt != null ) Stmt.close();

			iMsgId = 1;
			System.out.println("Insert Successfully");
		}
		else if ( iRecType == 2)
		{
			String sQry = "update tbl_user_master set user_name='"+ sUserName +"'";
			sQry += ",pwd='"+ sPwd +",";
			sQry += ",person_name='"+ sPwd +",";
			sQry += ",address='"+ sPwd +",";
			sQry += ",contactno='"+ sPwd +",";
			sQry += ",emailid='"+ sPwd +",";
			sQry += " where userid="+ iSno;
		System.out.println("tbl_user_master Qry : "+ sQry);					

			Statement Stmt = Con.createStatement();
			Stmt.executeUpdate(sQry);
			if ( Stmt != null ) Stmt.close();
					
			iMsgId = 3;
			System.out.println("Update Successfully");
		}
	}
	catch(Exception e)
	{	System.out.println(e);	}
	
	response.sendRedirect("../frm_msg.jsp?MsgID="+ iMsgId);
	
%>
</html>